<template>
  <div class="common_menu">
    <el-aside width="200px">
      <el-menu
        router
        :default-active="activepath"
        @open="handleOpen"
        @close="handleClose"
        background-color="#2578b5"
        text-color="#fff"
        active-text-color="ffd04b"
        v-for="(item, index) in menus"
        :key="index"
      >
        <template>
          <el-submenu :index="index + ''" v-if="!item.hidden">
            <template slot="title">
              <i :class="item.fontawesome"></i>
              <span> {{ item.name }} </span>
            </template>
            <el-menu-item-group
              v-for="(child, index) in item.children"
              :key="index"
            >
              <el-menu-item :index="child.path">
                <i :class="child.fontawesome"></i>
                <span> {{ child.name }} </span>
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </template>
      </el-menu>
    </el-aside>
  </div>
</template>

<script>
export default {
  name: "common_menu",
  data() {
    return {
      menus: [],
      activepath: "",
    };
  },
  created() {
    this.menus = [...this.$router.options.routes];
    // 默认显示菜单
    this.activepath = this.$router.currentRoute.path;
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss">
.common_menu {
  .el-aside {
    background-color: #2578b5;
    width: 100%;
    height: 100%;
    .el-menu {
      border-right-width: 0;
      .el-submenu {
        .el-submenu__title {
          height: 50px;
          line-height: 50px;
          font-size: 20px;
          text-align: left;
        }
        .el-menu-item-group__title {
          padding: 0;
        }
      }
      .el-menu-item {
        font-size: 17px;
      }
    }
  }
}
</style>
